/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import model.Usuario;
import xml.*;
import java.util.List;
import service.UsuarioService;
import service.ViajeService;
import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;

/**
 *
 * @author MIS DOCUMENTOS
 */
public class ConsumoXml2 extends AbstractCommandController {
 private String rutaViaje;
    private UsuarioService usuarioService;

    private static Logger loggers = null;
   
    public void setUsuarioService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

    public ConsumoXml2() {
        this.setCommandClass(Usuario.class);
    }

    @Override
        protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object form, BindException errors) throws Exception {
        Map model = new HashMap();
        String user;
        user = (String) request.getParameter("username");
        HacerConsumo d = new HacerConsumo();
        Usuario user1;
        List viajesXml =  d.ConsumoViaje(user);
        System.out.println("FATIMAAA");
        System.out.println("ID USUARIO"+ Long.parseLong(request.getParameter("ux")));
        
        user1 = (Usuario) usuarioService.getUsuario(Long.parseLong(request.getParameter("ux")));

        request.getSession().setAttribute("usuarioList", null);
        model.put("xmlViaje", viajesXml);
        model.put("usuario", user1);
        return new ModelAndView("viajesUsuarioApi", model);



    }
}
